package com.econ.powercloud.ems.controller;

import com.econ.powercloud.common.base.facade.enums.StatusType;
import com.econ.powercloud.common.base.facade.pojo.MsgResult;
import com.econ.powercloud.common.base.facade.pojo.PageResult;
import com.econ.powercloud.ems.pojo.ApiDataVO;

import java.util.List;

/**
 * @author zjr
 * @create 2021/7/16 上午9:40
 * @description 数据字典统一返回结果
 */
public class ApiBaseController {
    public ApiBaseController(){}

    protected MsgResult<PageResult<List<ApiDataVO>>> pageResult(PageResult<List<ApiDataVO>> t) {
        return this.executePageListHandler(StatusType.OK, t);
    }

    protected MsgResult<PageResult<List<ApiDataVO>>> executePageListHandler(StatusType statusType, PageResult<List<ApiDataVO>> t) {
        MsgResult<PageResult<List<ApiDataVO>>> msgResult = new MsgResult();
        msgResult.setData(t);
        msgResult.setStatus(statusType.getCode());
        msgResult.setStatusText(statusType.getStatusText());
        return msgResult;
    }

    protected <T> MsgResult<T> successHandler(T t) {
        return this.executeHandler(StatusType.OK, t);
    }

    public <T> MsgResult<T> executeHandler(StatusType statusType, T t) {
        MsgResult<T> msgResult = new MsgResult();
        msgResult.setData(t);
        msgResult.setStatus(statusType.getCode());
        msgResult.setStatusText(statusType.getStatusText());
        return msgResult;
    }

    public <T> MsgResult<List<T>> executeListHandler(StatusType statusType, List<T> t) {
        MsgResult<List<T>> msgResult = new MsgResult();
        msgResult.setData(t);
        msgResult.setStatus(statusType.getCode());
        msgResult.setStatusText(statusType.getStatusText());
        return msgResult;
    }
}
